//
//  main.m
//  03-homeWorkNSString NSArray NSMutableArray
//
//  Created by 韩旭 on 16/7/6.
//  Copyright © 2016年 基础. All rights reserved.
//
#import "libray.h"
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    
    // 1   截取字符串 "20|https://www.baidu.com" 中 "|" 前面和后⾯的字符串, 并输出
    // 2   向可变数组里存储 int、float、double、BOOL类型等数据(不能使用字面量)
    // 3   实现图书管理系统(BookManager类)：
    //    使用数组管理所有书籍(Book类)。
    //    BookManager类属性数组可以添加、删除。
    //    可以从数组根据书名查找书籍，并修改书籍的价格。
    //    展示所有书籍清单（书名）
#pragma mark - 作业1
    
#if 1
    {
        NSString *string = @"20|https://www.baidu.com";
        NSArray *arrString = [string componentsSeparatedByString:@"|"];
        NSLog( @"%@",arrString);
        
    }
#endif
#pragma mark - 作业2
#if 1
    {
        int a = 1;
        float b = 0.2;
        double c = 0.2222;
        BOOL d = YES;
        NSNumber *aNew = [NSNumber numberWithInt:a];
        NSNumber *bNew = [NSNumber numberWithFloat:b];
        NSNumber *cNew = [NSNumber numberWithDouble:c];
        NSNumber *dNew = [NSNumber numberWithBool:d];
        NSMutableArray *arrMutableArr = [NSMutableArray arrayWithObjects:aNew, bNew, cNew, dNew,  nil];
        NSLog(@"%@",arrMutableArr);
    }
#endif
#pragma mark - 作业3
#if 1
    {
        
        libray *book1 = [libray librayWithName:@"小王" Price:12];
        libray *book2 = [libray librayWithName:@"小李" Price:13];
        libray *book3 = [libray librayWithName:@"小赵" Price:14];
        libray *book4 = [libray librayWithName:@"小孙" Price:15];
        NSMutableArray *arrLibray = [NSMutableArray arrayWithObjects:book1, book2, book3, book4, nil];
        libray *book5 = [libray librayWithName:@"小红" Price:16];
#pragma mark - 添加联系人
#if 1
        {
            NSLog(@"-------分割线--------");
            [arrLibray addObject:book5];
            if ([book5.name isEqualToString:@""]) {
                NSLog(@"添加失败");
            } else {
                NSLog(@"添加成功");
            }
        }
#endif
        
#pragma mark - 删除联系人
#if 1
        {
            NSLog(@"------分割线------");
            for (int i = 0; i < arrLibray.count; i++) {
                libray *name = [arrLibray objectAtIndex:i];
                if ([name.name isEqualToString:@"小王"]) {
                    [arrLibray removeObjectAtIndex:i];
                }
            }
            for (libray *remName in arrLibray) {
                [remName outPut];
            }
        }
#endif
        
#pragma mark - 可以从数组根据书名查找书籍，并修改书籍的价格
#if 1
        {
            for (int i = 0; i < arrLibray.count; i++) {
                libray *name = [arrLibray objectAtIndex:i];
                if ([name.name isEqualToString:@"小红"]) {
                    name.price = 23;
                    [name outPut];
                }
            }
        }
#endif
        
#pragma mark - 展示所有书籍清单（书名）
#if 1
        {
            for (libray *name in arrLibray) {
                NSLog(@"%@",name.name);
            }
        }
#endif
        
    }
#endif
    
    return 0;
}
